
layui.config({
  base: '/layuiadmin/'
}).extend({
  index: 'lib/index' //主入口模块
  ,ztreeUtil: 'zTree_v3/ztreeUtil'
}).use(['index','ztreeUtil'], function(){

  var $ = layui.$
  ,form = layui.form
  ,admin = layui.admin;
  
  var uid = layui.router().search.id;
  var parentId = layui.router().search.parentId;
  if(uid != undefined && uid != ""){
      admin.req({
          type:"GET",
          url:"/api/admin/menu/"+uid,     
          dataType:"json",
          success:function(res){
              // 表示是修改数据
              var data = res.data;
              if(res.code==200){
                  form.val('menuForm', data);
              }
             
          },
          error:function(jqXHR){
              alert("发生错误："+ jqXHR.status);
          }
        });
      
  } else {
    form.val('menuForm', {
      parentId:parentId
    });
  }

  var tree = layui.ztreeUtil;
  var _tools = {
    saveTreeData: function(nodes){
      console.log(nodes);
      alert(nodes)
    }
  }
  window.tools = _tools;

  $('.treeShow').click(function () {
     tree.treeShow($(this))
  });

});